/**
 * Created by sun on 2015/3/12.
 */
package com.jbm.core.common;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

import java.util.HashMap;

public class OHCodeFactory implements ProtocolCodecFactory
{
	public static HashMap<String,String> t10to20 = null;
	public static HashMap<String,String> t20to10 = null;
	private final OHEncoder encoder; // 编码
	private final OHDecoder decoder; // 解码

	static
	{
		String[] t = "Media:Media|Login:Login".split("\\|");

		t10to20 = new HashMap<String,String>();
		t20to10 = new HashMap<String,String>();

		for ( int i = 0; i < t.length; i ++ )
		{
			String[] tt = t[i].split(":");

			t10to20.put(tt[0],tt[1]);
			t20to10.put(tt[1],tt[0]);
		}
	}

	public OHCodeFactory(String charset)
	{
		encoder = new OHEncoder(charset);
		decoder = new OHDecoder(charset);
	}

	public ProtocolEncoder getEncoder(IoSession session)
	{
		return encoder;
	}

	public ProtocolDecoder getDecoder(IoSession session)
	{
		return decoder;
	}
}